<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="/images/favicon.ico"  type="image/x-icon">

  <title>在线考试系统</title>

  <link href="/css/style.css" rel="stylesheet">
  <link href="/css/style-responsive.css" rel="stylesheet">

  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="/js/html5shiv.js"></script>
  <script src="/js/respond.min.js"></script>
  <![endif]-->
</head>

<body class="horizontal-menu-page">

<section id="index_war">

    <div th:replace="~{user/commons/common :: commonhead(active='index.html')}"></div>
    <!--正文开始-->
    <div class="wrapper">
        <div class="col-md-12">
            <!--考试/公告开始-->
            <div class="col-md-8">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            首页
                        </div>
                            <div id="pie-chart-donut" class="pie-chart">
                                <div id="pie-donutContainer" style="width: 100%;height:400px; text-align: left;">
                                </div>
                            </div>
                    </div>
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        考试/通告
                    </div>
                    <div class="panel-body" th:each="p : ${paper}">
                        <input class="hidden" th:value="${p.pId}">
                        <td>
                            <a th:text="${p.pName}" href="javascript:;" th:onclick="goExam([[${p.pId}]],[[${p.pName}]],[[${p.pdStatus}]],[[${p.startTime}]],[[${p.endTime}]])" style="color: #65CEA7;"></a>
                        </td>
                        <td>
                            <span style="float: right" th:if="${p.pdStatus}==0" th:text="未开始" class="label label-info"></span>
                            <span style="float: right"  th:if="${p.pdStatus}==1" th:text="进行中" class="label label-primary"></span>
                            <span style="float: right"  th:if="${p.pdStatus}==2" th:text="已结束" class="label label-danger"></span>
                        </td>
                        <td class="hidden" th:value="${#temporals.format(p.startTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                        <td class="hidden"  th:value="${#temporals.format(p.endTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                    </div>
                </div>
            </div>
            <!--统计开始-->
            <div class="col-md-4">
                <div class="col-md-12">
                    <div class="panel panel-success">
                        <div class="panel-heading">
                            <h3 class="panel-title">统计</h3>
                        </div>
                        <div class="panel-body">

                            <p>今日参与答题数 ： <a style="color: #4E6CA3" th:text="${finishNum}"></a></p>
                            <p>今日答题正确数 ： <a style="color: #4E6CA3"  th:text="${rightNum}"></a></p>

                        </div>
                    </div>
                </div>
                <!--排名开始-->
                <div class="col-md-12">
                    <div class="panel panel-success">
                        <div class="panel-heading">
                            <h3 class="panel-title">排名</h3>
                        </div>
                        <div class="panel-body">
                            <table  class="table  table-hover general-table">
                                <thead>
                                <tr>
                                    <th>排名</th>
                                    <th>用户名</th>
                                    <th>专业</th>
                                    <th>解决数</th>
                                </tr>
                                </thead>

                                <tbody>
                                <tr th:each="ranks : ${userList}">
                                    <td th:text="${ranks.getRId()}"></td>
                                    <td th:text="${ranks.getUserName()}"></td>
                                    <td th:text="${ranks.getProfession()}"></td>
                                    <td th:text="${ranks.getResultNum()}"></td>
                                </tr>
                                </tbody>
                            </table>

                            <!--分页-->
                            <div th:fragment="page"><!--定义用于被显示列表页包含-->
                                <head>
                                    <style>
                                        .page-item {
                                            padding: 1px 5px;
                                            border: 1px solid #afafaf;
                                            margin-left: 3px
                                        }

                                        .page-item.active {
                                            color: red;
                                            border: 1px solid red;
                                        }
                                    </style>
                                </head>
                                <div style="float: left" th:if="${page.pages>0}">
                                    当前第<span th:text="${page.current}"></span>页,共<span
                                        th:text="${page.pages}"></span>页,总记录数<span th:text="${page.total}"></span>
                                </div>
                                <div style="float: right" th:if="${page.pages>0}">
                                    <a th:href="@{${jumpUrl}}" th:text="首页" th:if="${page.current>1}" th:class="page-item"></a>
                                    <a th:href="@{${jumpUrl}+${page.current-1}}" th:text="上一页" th:class="page-item"
                                       th:if="${page.current>1}"></a>
                                    <a th:href="@{${jumpUrl}+${i}}"
                                       th:each="i :${#numbers.sequence(1, page.pages)}" th:text="${i}"
                                       th:class="${page.current == i}? 'page-item active' :'page-item' "></a>
                                    <a th:href="@{${jumpUrl}+${page.current+1}}" th:text="下一页" th:class="page-item"
                                       th:if="${page.current<page.pages}"></a> <a
                                        th:href="@{${jumpUrl}+${page.pages}}" th:text="尾页" th:class="page-item"
                                        th:if="${page.current<page.pages}"></a>
                                </div>
                            </div>
                            <!--分页结束-->

                        </div>
                    </div>
                </div>
                <!--排名结束-->
            </div>
            <!--统计结束-->



            <!--考试/公告结束-->
        </div>

    </div>
    <!--正文结束-->

    <!--底部开始-->
    <footer class="sticky-footer">
        2022 &copy;<a href="https://www.pdsu.edu.cn/" target="_blank">平顶山学院软件应用双创实验室提供技术支持</a>
    </footer>
    <!--底部结束-->

</section>

<div th:replace="~{user/commons/common :: commonupdatePwd}"></div>

<script src="/js/jquery-1.10.2.min.js"></script>
<script src="/js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="/js/jquery-migrate-1.2.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/modernizr.min.js"></script>
<script src="/js/jquery.nicescroll.js"></script>
<!--图表-->


<script src="/js/scripts.js"></script>

<script type="text/javascript">

    function goExam(pid,pName,pdStatus,startTime,endTime) {
        var start = new Date(startTime).getTime();
        var end = new Date(endTime).getTime();
        var str = new Date().getTime();

        if (pdStatus > 1) {
            alert("考试已经结束！")
        }else{
            if(start <= str && str <= end){
                if (confirm("是否要进入"+pName+"")) {
                    $.ajax({
                        url:"/user/paper/isScore",
                        type:"post",
                        data:JSON.stringify({
                            pId:pid
                        }),
                        contentType: "json/application",
                        //定义回调响应的数据格式为JSON字符串，该属性可以省略
                        dataType: "json",
                        // 成功响应的结果
                        success: function (data) {
                            console.log(data)
                            if (data.code == 200){
                                alert("您已完成了本次考试，成绩为："+data.score+"分!")
                                return;
                            }else if(data.code == 400){
                                $('#index_war').load('/user/paper/toPaperDetail?pid='+pid);
                                toFirst(pid)
                            }else{
                                alert("系统出现了问题，请重试")
                            }

                        }
                    })

                }else{
                    return
                }
            }else if (start > str){
                alert("还没有到指定时间,请稍后重试!")
            }else if (str > end){
                alert("考试时间已过！")
            }
        }
    }

    // 修改密码
    $("#pwd_btn").click(function() {
        $("#pwd_btn").blur();
        if (confirm("是否确定修改?")){
            var submit = true;
            var oldPwd = $("#oldPwd").val(); //原始密码
            var newPwd = $("#newPwd").val(); //新密码1
            var newPwd2 = $("#newPwd2").val(); //新密码2

            if ((oldPwd && newPwd && newPwd2) == '') {
                $("#tip").html("密码不能为空");
                $("#tip").show();
                submit = false;
            }
            if(submit){
                $.ajax({
                    type:"post",
                    url:"/user/updatePwd",
                    data: JSON.stringify({
                        oldPwd : oldPwd,
                        newPwd : newPwd,
                        newPwd2 : newPwd2
                    }),
                    contentType: "application/json;charset=utf-8",
                    //定义回调响应的数据格式为JSON字符串，该属性可以省略
                    dataType: "json",
                    success:function (data){
                        if(data.code == 200 ){
                            $("#tip").hide();
                            $("#pwd_form").submit();
                            alert("修改成功，请重新登录!")
                            window.location.href = "/user/logout"
                        }else if(data.code != 200){
                            $("#tip").html(data.info);
                            $("#tip").show();
                        }
                    }
                });
            }
        }
    });

</script>


<div th:replace="~{user/commons/common :: commonPaperJs}"></div>

</body>
</html>
